package cn.dlc.com.sort;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * @author 邓立川
 * @date 2021/3/14 11:09
 * @desc 测试希尔排序的时间复杂度，对比的是希尔排序和插入排序
 */
public class Demo12 {

    public static void main(String[] args) throws Exception {

        ArrayList<Integer> list = new ArrayList<>();

        InputStream io = Demo12.class.getClassLoader().getResourceAsStream("reverse_arr.txt");
        InputStreamReader ioReader = new InputStreamReader(io);
        BufferedReader fileReader = new BufferedReader(ioReader);

        String line = null;
        while((line = fileReader.readLine()) != null) {
            int result = Integer.parseInt(line);
            list.add(result);
        }

        Integer[] arr = new Integer[list.size()];
        list.toArray(arr);

        testHill(arr);
    }

    private static void testInsert(Integer[] arr){
        long start = System.currentTimeMillis();
        Demo10.InsertSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("插入排序用时：" + (end - start));
    }

    private static void testHill(Integer[] arr){
        long start = System.currentTimeMillis();
        Demo11.HillSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("插入排序用时：" + (end - start));
    }
}
